<?php
namespace app\demo\model;

use think\Model;
use think\model\concern\SoftDelete;

class Brand extends Model
{
    protected $pk='brand_id';
    //获取器
    public function getRecommendedJiaAttr($v,$d)
    {
        $arr = ["<img height='50px' src='/static/demo/images/X.jpg' alt=''>", "<img height='50px' src='/static/demo/images/√.jpg' alt=''>"];
        return $arr[$d['recommended']];
    }
    public function getIfShowJiaAttr($v,$d)
    {
        $arr = ["<img height='50px' src='/static/demo/images/X.jpg' alt=''>", "<img height='50px' src='/static/demo/images/√.jpg' alt=''>"];
        return $arr[$d['if_show']];
    }
    //搜索器
    public function searchBrandNameAttr($q,$v,$d)
    {
        $q->where('brand_name','like','%'.$v.'%');
    }
    public function searchIfShowAttr($q,$v,$d)
    {
        $q->where('if_show','=',$v);
    }
    public function searchRecommendedAttr($q,$v,$d)
    {
        $q->where('recommended','=',$v);
    }
    public function searchBrandLogoAttr($q,$v,$d)
    {
        if($v==1){
            $q->where('brand_logo','<>',"");
        }else{
            $whereOr[]=['brand_logo','=',null];
            $whereOr[]=['brand_logo','=',''];
            $q->where(function ($query) use($whereOr){
                $query->whereOr('brand_logo','=','');
            });
        }

    }
    //品牌查询
    public static function getBrandList($where,$whereOr,$get='')
    {
        $list=Brand::name('brand')
            ->withSearch(array_keys($where),$where)
            ->order('sort_order','asc')
            ->paginate([
                'list_rows'=>5,
                'query'=>$get
            ]);

        return $list;
    }
}